﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using WebBridge.Proxy;

namespace WebBridge
{
    public class Portal
    {
        private static readonly IDictionary<string, FxProxy> Map;
        static Portal()
        {
            var proxyList = new[]
                {
                    new FxProxy(typeof(IB1AHConnection), B1AHConnection.Instance),
                    new FxProxy(typeof(IXSEngineConnection), XSEngineConnection.Instance),
                };

            Map = new Dictionary<string, FxProxy>();
            foreach (var proxy in proxyList)
            {
                Map.Add(proxy.Name, proxy);
            }
        }

        public static int Invoke(string argument)
        {
            try
            {
                var args = FxArgs.Deserialize(argument);
                Map[args.Target].Invoke(args);
                return 0;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return 1;
            }
        }
    }
}
